﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using HigLabo.WindowsAzure.RestService.Extensions;

namespace HigLabo.WindowsAzure.RestService.ServiceManagement
{
    public class StorageService
    {
        public static readonly String ElementName = "StorageService";

        public String Url { get; private set; }
        public String ServiceName { get; set; }
        public StorageServiceProperties StorageServiceProperties { get; private set; }
        public Endpoints Endpoints { get; private set; }
        public StorageServiceKeys StorageServiceKeys { get; private set; }

        public StorageService(XElement xml)
        {
            XElement el;            
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }
            this.Url = xml.ValueOrEmpty("Url");
            this.ServiceName = xml.ValueOrEmpty("ServiceName");
            el = xml.ElementByLocalName(StorageServiceProperties.ElementName);
            if (el != null)
            {
                this.StorageServiceProperties = new StorageServiceProperties(el);
            }
            el = xml.ElementByLocalName(Endpoints.ElementName);
            if (el != null)
            {
                this.Endpoints = new Endpoints(this.ServiceName);
            }
            el = xml.ElementByLocalName(StorageServiceKeys.ElementName);
            if (el != null)
            {
                this.StorageServiceKeys = new StorageServiceKeys(el);
            }
        }
    }
}
